package frame;

import java.awt.Container;
import java.awt.EventQueue;
import java.awt.event.MouseEvent;  
import java.awt.event.MouseListener; 

import javax.swing.JFrame;

public class TestFrame extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JFrame frame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TestFrame window = new TestFrame();
					window.setVisible(true);
					window.setBounds(0, 0, 800, 630);
					window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					window.getContentPane().setLayout(null);
					window.setResizable(false);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public TestFrame() {    
		initialize();
	}
	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		// TODO Auto-generated constructor stub  
        Container container = getContentPane();  
        container.addMouseListener(new MouseListener() {  
  
            @Override  
            public void mouseClicked(MouseEvent e) {  
                // TODO Auto-generated method stub  
                System.out.print("单击了鼠标按键，");  
                int i = e.getButton();  
                if (i == MouseEvent.BUTTON1)  
                    System.out.print("单击的是鼠标左键，");  
                if (i == MouseEvent.BUTTON2)  
                    System.out.print("单击的是鼠标中键，");  
                if (i == MouseEvent.BUTTON3)  
                    System.out.print("单击的是鼠标右键，");  
                int clickCount = e.getClickCount();  
                System.out.println("单击次数为" + clickCount + "下");  
            }  
  
            @Override  
            public void mousePressed(MouseEvent e) {  
                // TODO Auto-generated method stub  
                System.out.print("鼠标按键被按下，");  
                int i = e.getButton();  
                if (i == MouseEvent.BUTTON1)  
                    System.out.println("按下的是鼠标左键");  
                if (i == MouseEvent.BUTTON2)  
                    System.out.println("按下的是鼠标中键");  
                if (i == MouseEvent.BUTTON3)  
                    System.out.println("按下的是鼠标右键");  
            }  
  
            @Override  
            public void mouseReleased(MouseEvent e) {  
                // TODO Auto-generated method stub  
                System.out.print("鼠标按键被释放，");  
                int i = e.getButton();  
                if (i == MouseEvent.BUTTON1)  
                    System.out.println("释放的是鼠标左键");  
                if (i == MouseEvent.BUTTON2)  
                    System.out.println("释放的是鼠标中键");  
                if (i == MouseEvent.BUTTON3)  
                    System.out.println("释放的是鼠标右键");  
            }  
  
            @Override  
            public void mouseEntered(MouseEvent e) {  
                // TODO Auto-generated method stub  
                System.out.println("光标移入组件");  
            }  
  
            @Override  
            public void mouseExited(MouseEvent e) {  
                // TODO Auto-generated method stub  
                System.out.println("光标移出组件");  
            }  
            
        }); 
	}  
}
